<?php
declare (strict_types = 1);

namespace app\home\controller;

use app\common\controller\Frontend;
use think\facade\Db;
use think\facade\View;

class Index extends Frontend
{
    public function initialize() {
        parent::initialize();
    }

    public function index() {

        // 获取已登录后的用户信息
        global $userinfo;
        $uid = $userinfo['id'];
        $info = [];
        $info['system'] = 0;
        View::assign('info', $info);

        $totaldocnum = Db::name('doc_con')->count('id');
        View::assign('totaldocnum', $totaldocnum);

        # 获取幻灯片
        $mapslide['status'] = 1;
        $slide =Db::name('slide')->where($mapslide)->limit(6)->order('ordid desc')->select();
        View::assign('slide', $slide);

        //首页推荐专辑
        $tjzj = Db::name('album')->where(array('zhiding'=>'1','status'=>'1'))->select();
        $tjzjs =[];
        //获取专辑下3个最新文档
        foreach ($tjzj as $k => $v) {
            $doc= Db::name('doc_con')->where(array('zjid'=> $tjzj[$k]['id'],'status'=> 1,'del_status'=> 1,'convert_status'=> 2))->limit(3)->order('id DESC')->select()->toArray();
            $tjzjs[$k]['zhuanji']=$doc;
            $tjzjs[$k]['id']=$tjzj[$k]['id'];
            $tjzjs[$k]['img']=$tjzj[$k]['img'];
            $tjzjs[$k]['title']=$tjzj[$k]['title'];
        }

        View::assign('tjzj', $tjzjs);
        //重写首页最新文档
        $docMap['status'] = 1;
        $docMap['convert_status'] = 2;
        $docMap['del_status'] = 1;
        $indexDocList = Db::name('doc_con')->where($docMap)->limit(60)->order('id desc')->select();
        View::assign('indexDocList', $indexDocList);
        return view();

    }


}
